package com.scsj.supermarket.adapter;
import android.graphics.Paint;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scsj.supermarket.R;
import com.scsj.supermarket.bean.QueryGoodsInTradeBean;

import java.util.ArrayList;
import java.util.List;

/**
 *  首页商品列表
 */

public class ShopTradeCircleAdapter extends BaseQuickAdapter<QueryGoodsInTradeBean.DataBean.ListBean,BaseViewHolder> {
    //用来存放所有商圈下商品的集合
    private List<QueryGoodsInTradeBean.DataBean.ListBean> goodsInTrades= new ArrayList<>();
    public ShopTradeCircleAdapter(List data) {
        super(R.layout.item_shop_list_base_layout1, data);
        this.goodsInTrades= data;
    }

    @Override
    protected void convert(BaseViewHolder helper, QueryGoodsInTradeBean.DataBean.ListBean item) {

        for (int i = 0 ;i<goodsInTrades.size();i++){

            ImageView goodLogoIv= helper.getView(R.id.index_icon_iv);
            String goodsUrl= goodsInTrades.get(i).getGoodsImage();
            Glide.with(mContext).
                    load(goodsUrl).
                    diskCacheStrategy(DiskCacheStrategy.RESULT).
                    thumbnail(0.5f).
                    placeholder(R.drawable.ic_launcher_background).
                    priority(Priority.LOW).
                    error(R.drawable.ic_launcher_background).
                    fallback(R.drawable.ic_launcher_background).
                    into(goodLogoIv);
            helper.setText(R.id.index_address_tv,goodsInTrades.get(i).getStoreName());
            helper.setText(R.id.index_name_tv,goodsInTrades.get(i).getGoodsName());
            helper.setText(R.id.index_func_tv,goodsInTrades.get(i).getGoodsIntroduce());

            helper.setText(R.id.index_num_tv,"销量"+goodsInTrades.get(i).getMonthSellNum());
            helper.setText(R.id.index_collect_tv,"收藏"+goodsInTrades.get(i).getCollectNum());
            helper.setText(R.id.index_price_tv, goodsInTrades.get(i).getGoodsPrice()+"");
            helper.setText(R.id.index_oldprice_tv,goodsInTrades.get(i).getGoodsPromotionPrice()+"");

            TextView oldPriceTv= helper.getView(R.id.index_oldprice_tv);
            oldPriceTv.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG ); //中间横线（删除线）
        }
    }
}
